<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>邻近处理程序的执行顺序</title>
</head>
<body>
  <script>
    let p1 = Promise.resolve();
    let p2 = Promise.reject();

    p1.then(() => setTimeout(console.log, 0, 1));
    p1.then(() => setTimeout(console.log, 0, 2));
    // 1
    // 2

    p2.catch(() => setTimeout(console.log, 0, 3));
    p2.catch(() => setTimeout(console.log, 0, 4));
    // 3
    // 4

    
    p2.catch(() => setTimeout(console.log, 0, 5));
    p2.catch(() => setTimeout(console.log, 0, 6));
    // 5
    // 6

    p1.finally(() => setTimeout(console.log, 0, 7));
    p1.finally(() => setTimeout(console.log, 0, 8));
    // 7
    // 8
  </script>
</body>
</html>